home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld 1998 June
/
Macworld (1998-06).dmg
/
Shareware World
/
Info
/
For Developers
/
MacsBug 6.5.4a4
/
Building dcmds
/
C Samples
/
Heap.c
< prev
next >
Wrap
Text File
|
1998-02-11
|
3KB
|
121 lines
/*
File: Heap.c
Contains: A sample dcmd which dumps heap blocks.
Written by: JM3 = Jim Murphy
Copyright: © 1988, 1994, 1996 by Apple Computer, Inc., All Rights Reserved.
Change History (most recent first):
<4> 25-Jan-96 JM3 Added sample build commands.
<3> 10-Dec-94 JM3 Updated for new format 3 dcmd requirements.
<2> 1-Sep-94 JM3 Included string.h so we build with no warnings with -r.
The following MPW commands will build the dcmd and copy it to the "Debugger Prefs" file
in the System folder. The dcmd's name in MacsBug will be the name of the file built by
the Linker.
C Heap.c
Link -o Heap -sg Main=STDCLIB,STDIO,SANELIB dcmdGlue.a.o Heap.o ∂ ∂
"{Libraries}Runtime.o" "{CLibraries}StdCLib.o"
BuildDcmd Heap 195 -format3
Echo 'include "Heap";' | Rez -a -o "{SystemFolder}Debugger Prefs"
*/
#include <Memory.h>
#include <Types.h>
#include <string.h>
#include "dcmd.h"
void NumberToHex (long number, Str255 hex)
{
Str255 digits = "0123456789ABCDEF";
int n;
strcpy (hex, &".00000000");
hex[0] = 8;
for (n = 8; n >= 1; n--)
{
hex[n] = digits[number % 16];
number = number / 16;
}
} // NumberToHex
pascal void DisplayBlockInfo (long blockAddress, long blockLength, long masterPtr, short blockType, Boolean locked, Boolean purgeable, Boolean resource)
{
Str255 value;
NumberToHex (blockAddress, value);
dcmdDrawLine (value);
NumberToHex (blockLength, value);
dcmdDrawString ("\p ");
dcmdDrawString (value);
if (blockType == relocatableBlock)
{
NumberToHex (masterPtr, value);
dcmdDrawString ("\p ");
dcmdDrawString (value);
dcmdDrawString ("\p ");
if (locked)
dcmdDrawString ("\pLocked ");
if (purgeable)
dcmdDrawString ("\pPurgeable ");
if (resource)
dcmdDrawString ("\pResource ");
}
} // DisplayBlockInfo
pascal void CommandEntry (dcmdBlock* paramPtr)
{
static const char usageStr[] = "\p";
switch (paramPtr->request)
{
case dcmdInit:
break;
case dcmdHelp:
dcmdDrawLine("\pDisplays information about all heap blocks.");
break;
case dcmdGetInfo:
* (long *) &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->dcmdVersion = 0x03008000; // version 3.0 final
BlockMoveData(&usageStr, &((GetInfoRequestBlockPtr) paramPtr->requestIOBlock)->usageStr, usageStr[0]+1);
break;
case dcmdDoIt:
// Draw the column labels
dcmdDrawLine ("\p Address Length Mstr Ptr");
// The MacsBug heap iterator will call DisplayBlockInfo once for each block in the heap.
dcmdForAllHeapBlocks (DisplayBlockInfo);
break;
// Version 3 and newer dcmds must quietly ignore requests we don't recognize.
default:
break;
}
} // CommandEntry